package com.abel;

import java.util.ArrayList;
import java.util.List;

/**
 * Hello world!
 *
 */
public class App 
{
    public static List<Object> listA = new ArrayList();
    public static List<Object> listB = new ArrayList();
    public static List<Object> list = new ArrayList();
    public static A a = new A(listA);
    public static B b = new B(listB);
    public static void main( String[] args )
    {


    }
}
class A {
       private List<Object> productA;
       public A(List<Object> productA){
           this.productA = productA;
       }
       public void produce(){
           synchronized (this.productA){
               if(this.productA.size()==2){
                   try {
                       this.productA.wait();
                       System.out.println("product A full please wait");
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
               System.out.println("product a new product A");
               this.productA.add(new Object());
           }

       }
}
class B{
    private List<Object> producttB;
    public B(List<Object> productB){
        this.producttB = producttB;
    }
    public void produce(){
        synchronized (this.producttB){
            if(producttB.size()==1){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        this.producttB.add(new Object());
    }
}
